from sqlalchemy import Column, Integer, String, DateTime,func
from pydantic import ConfigDict
import uuid
from core.dependencies import Base

class File(Base):
    __tablename__ = 'file'
    uid = Column(Integer, primary_key=True, index=True, autoincrement=True)
    file_id = Column(String(32), default=lambda: uuid.uuid4().hex, nullable=False, unique=True, index=True)
    file_name = Column(String(255), unique=True, nullable=False)
    file_path = Column(String(255), unique=True, nullable=False)
    file_type = Column(String(32), nullable=False)
    knowbase_id = Column(String(32), nullable=False, index=True)
    create_date = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
    user_id = Column(String(255), nullable=False, default='000000000000000000000000')
    
    
    model_config = ConfigDict(from_attributes=True)
    
    def __repr__(self):
        return f"<File(file_id={self.file_id}, uid={self.uid})>"

class KnowledgeBase(Base):
    __tablename__ = 'knowledge_base'
    __table_args__ = {"schema": "public"}
    uid = Column(Integer, primary_key=True, index=True, autoincrement=True)
    know_base_id = Column(String(32), default=lambda: uuid.uuid4().hex, nullable=False, unique=True, index=True)
    # 其他字段
    know_base_name = Column(String(255), unique=True, nullable=False)
    create_date = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
    create_user_id: Column[str] = Column(String(32), nullable=False, default='000000000000000000000000')

    def __repr__(self):
        return f"<KnowledgeBase(know_base_id={self.know_base_id}, uid={self.uid})>"